package main

import (
	"fmt"
	"io"
	"net/http"
)

// 自定义路由

func main() {
	router := &http.Server{
		Addr:    ":80",
		Handler: &RouterMux{},
	}

	if err := router.ListenAndServe(); err != nil {
		fmt.Println("Listen failed, ", err)
	}
}

type RouterMux struct {
}

func (p *RouterMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	switch r.URL.Path {
	case "/hello":
		io.WriteString(w, "hello router")
	case "/demo":
		io.WriteString(w, "demo router")
	default:
		io.WriteString(w, "404 page not found")
	}
}
